package net.wanho.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import net.wanho.dto.RoleAuthDTO;
import net.wanho.mapper.RoleAuthMapper;
import net.wanho.po.RoleAuth;
import net.wanho.service.RoleAuthService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 32033
 * @description 针对表【role_auth(角色权限表)】的数据库操作Service实现
 * @createDate 2025-01-11 17:01:23
 */
@Service
@RequiredArgsConstructor
public class RoleAuthServiceImpl extends ServiceImpl<RoleAuthMapper, RoleAuth>
        implements RoleAuthService {

    private final RoleAuthMapper roleAuthMapper;

    @Override
    public List<Integer> getByUserId(Integer id) {
        System.out.println("id = " + id);
        List<Integer> ids = roleAuthMapper.getByUserId(id);
        return ids;
    }

    @Override
    public void updateAuth(RoleAuthDTO roleDTO) {
        roleAuthMapper.deleteByRoleId(roleDTO.getRoleId());
        roleDTO.getAuthIds().forEach(authId -> {
            RoleAuth roleAuth = new RoleAuth();
            roleAuth.setRoleId(roleDTO.getRoleId());
            roleAuth.setAuthId(authId);
            roleAuthMapper.insert(roleAuth);
        });
    }
}




